<template name="sendcar">
	<!-- 库间移位  ， 组织间移位 ， 公司间移位 申请单 列表 -->
	<view class="mypage">

		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="输入申请人" v-model="keyword"></input>
			</view>
			<view class="action">
				<button class="cu-btn bg-blue shadow-blur round" @tap="handelSearch">搜索</button>
			</view>
		</view>
		
		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" 
			v-for="(item,index) in orderList" :key="index" @click="openDetail(index)">  <!-- @click="openDetail(index)" -->
				
				<view class="flex-just-between bottom-border top-wrap">
					<text class="text-blue text-bold"> 单号 ：{{ item.BILLNO || '000' }}</text>
					<view class="cu-capsule radius">
						<view class='cu-tag bg-blue sm'>
							<text class='cuIcon-medal'></text>
						</view>
						<view class="cu-tag line-brown sm">
							{{ index+1}}
						</view>
					</view>
				</view>
				
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">集团：</text>
					<text>{{ item.GROUPNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-red"></text>
					<text class="card-label text-black">组织：</text>
					<text>{{ item.ORGNAME || '' }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text class="card-label text-black">部门：</text>
					<text> {{ item.DEPTNAME || '' }}</text>
				</view>
				<!-- <view class="card-list-row-1">
					<text class="cuIcon-title text-green"></text>
					<text class="card-label text-black">供应商：</text>
					<text>{{ item.SUPPLYNAME || '' }}</text>
				</view> -->
				<view class="card-list-row-1">
					<text class="cuIcon-title text-blue"></text>
					<text class="card-label text-black">申请人：</text> 
					<text>{{ item.MOVER || item.PURER }}</text>
				</view>
				<view class="card-list-row-1">
					<text class="cuIcon-title text-gray"></text>
					<text class="card-label text-black">日期：</text> 
					<text>{{ item.CREATIONTIME? item.CREATIONTIME.split(' ')[0] :'' }}</text>
				</view>
				
			</view>
		
		</view>
		
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import api from '@/common/api.js'
	import utils from '@/common/util.js'
	let _self, page=1, total=1, pageTitle,busType,requeryURL;
	let query = {
			"category":"BILLNO",
			"page":1,
			"rows":10,
			"sidx":"CREATIONTIME",
			"sord":"desc",
			"queryJson":{},
			"userId":"",
			"account":"admin"
	}
	let bsTypeKey = {
		ware:1,
		org:3,
		company:2
	}
	let queryJson = { BTYPE:1,BILLSTATUS :1 };
	// {BTCATEGORY:1,MOVETYPE:0},
	export default {
		computed: mapState(['userInfo']),
		data() {
			return {
				orderList: [],
				keyword:''
			};
		},
		onLoad(params) {
			_self = this 
			console.log(params);
			page = 1;
			total = 1 ;
			busType = params.type
			pageTitle = params.title
			queryJson = {}
			getApp().globalData.queryJsonLS = null
			queryJson.BTYPE = bsTypeKey[busType]
			query.account = this.userInfo.Account
			query.userId = this.userInfo.UserId
			requeryURL = this.userInfo.BaseURL + api.apiPublic.DisplacementList
			// GetMoveList
			
			this.getNewsList();
		},
		// 导航栏点击
		onNavigationBarButtonTap(e) {
			const Code = {
				'ware':'menu1014',
				'org':'menu1015',
				'company':'menu1015',
			}
			if(e.index==0){
				this.listenOnce()
				uni.navigateTo({
					url: '/pages/public/query?type=' + Code[busType] 
				})
			}else{
				uni.navigateTo({
					url:'new_shift_manual?type='+busType+'&typeKey='+queryJson.BTYPE
				})
			}
		},  
		//下拉刷新
		onPullDownRefresh : function(){
			// 重置分页及数据
			page = 1;
			total = 1 ;
			this.orderList = [] ;
			this.getNewsList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			uni.showToast({"title":"数据已刷新", icon:"none"});
		},
		// 加载更多
		onReachBottom : function(){
			this.getNewsList();
		},
		methods:{
			// 初始监听
			listenOnce() {
				uni.$off('reload')
				uni.$once("reload", function(data) {
					queryJson= { ...queryJson , ...data }
					getApp().globalData.queryJsonLS = queryJson
					_self.handelSearch()
				});
			},
			handelSearch(){
				queryJson.BILLNO = _self.keyword ;
				page = 1;
				total = 1 ;
				this.orderList = [] ;
				this.getNewsList();
			},
			getNewsList(){
				if( page>total ){return uni.showToast({
					icon:'none',
					title:'没有数据了。'
				})}
				query.page = page ;
				query.queryJson = JSON.stringify(queryJson);
				console.log(query);
				console.log(requeryURL);
				this.axios({
					url: requeryURL ,
					data: query,
					isLoading:1
				}).then(res=>{
					let {IsSuccess, Result,Message} = res ;
					// console.log(res);
					_self.setPageTitle(pageTitle+'列表('+Result.records+')')
					_self.orderList = [... _self.orderList, ...Result.rows ]
					total = Result.total
					page++
				})
			},
			
			setPageTitle(d){
				uni.setNavigationBarTitle({
				    title: d
				});
			},
			
			openDetail(e){
				// console.log(e);
				let Path = '/pages/tab04/new_shift/over_out?id='+_self.orderList[e].BILLNO+ '&busType='+busType +'&typeKey='+queryJson.BTYPE+ '&data='+ encodeURIComponent(JSON.stringify(_self.orderList[e]));
				// console.log(Path);
				uni.navigateTo({
					url:  Path 
				})
			},
			
			openScan(id, index) {
				uni.scanCode({
					onlyFromCamera: true,
					success: function(res) {
						// console.log(res)
						if (res.scanType != 'QR_CODE') {
							return uni.showToast({
								icon: 'none',
								title: '类型错误，请重新扫描'
							})
						}
						let t = res.result ;
						_self.keyword = t ;
						_self.handelSearch()
					}
				});
			
			}
			
		}
	}
</script>

<style scoped>
	
	.card-list-wrapper {
		width: 710upx;
		height: 100upx;
		margin: 0 auto;
	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}
	.card-label{
		display: inline-block;
		width: 150upx;
	}
	.top-border{
		border-top: 1upx solid rgba(0,0,0,.1);
	}
	.top-wrap{
		padding-bottom: 20upx;
		margin-bottom: 20upx;
	}
	.bottom-border{
		border-bottom: 1upx solid rgba(0,0,0,.1);
	}
	.btn-wrap{
		padding-top: 20upx;
	}
</style>
